
// import configs from 'configs';
// console.log(configs);

// 本地存储封装
class Store {
  constructor() {
    this.store = window.localStorage;
    // this.prefix = configs.settings.gbs.db_prefix;
  }
  set(key, value, fn) {
    try {
      value = JSON.stringify(value);
    } catch (e) {
      // value = value;
    }
    this.store.setItem(key, value);
    fn && fn();
  }
  get(key, fn) {
    if (!key) {
      throw new Error('没有找到key');
    }
    if (typeof key === 'object') {
      throw new Error('key不能是一个对象');
    }
    var value = this.store.getItem(key);
    if (value !== null) {
      try {
        value = JSON.parse(value);
      } catch (e) {
        throw new Error(e);
      }
    }
    return value;
  }
  remove(key) {
    this.store.removeItem(key);
  }
}
export default new Store();
